<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Request;
use think\Session;

class Home extends Controller{
    public function home(){
        return view();
    }
    //展示左侧菜单栏
    public function show(){
        $data=Db::table('category')->select();
        $a=$this->getTree($data);
        $this->assign('data',$a);
        if(Session::has('name','think')){
            $user=Session::get('name','think');
            $uname=$user['u_name'];
            $this->assign('uname',$uname);
        }
        return view('home');
    }
    public function getTree($data,$pid=0){
        $arr=array();//定义数组
        foreach($data as $key=>$val){
            if($val['parent_id']==$pid){
                $arr[$key]=$val;//取出值，把每个值放进单独的数组中
                $arr[$key]['child']=$this->getTree($data,$val['cat_id']);
            }
        }
        return $arr;
    }
    //退出.
    public  function layout(){
        Session::delete('name','think');
        $this->redirect('Index/index');
    }
}